<template>
  <div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="车牌" prop="carId">
        <el-input v-model="ruleForm.carId"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="carIn()">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        carId: '',
      },
      rules: {
        carId: [
          { required: true, message: '输入车牌', trigger: 'blur' },
          { min: 7, max: 7, message: '输入正确车牌', trigger: 'blur' }
        ],

      }
    };
  },
  methods: {
    carIn(){
      let url = 'http://localhost:8080/car/carOut?carId='+this.ruleForm.carId
      this.axios
          .create({'headers': {'Authorization': localStorage.getItem('jwt')}})
          .post(url,this.ruleForm).then((response)=>{
        let responseBody =response.data;
        if (responseBody.code==200){
          console.log(responseBody.data)
          window.location.href = "http://localhost:8080/pay/confirm?price="+26
          this.$message({
            showClose: true,
            message: '车辆离开成功！',
            type: 'success'
          });
        } else{
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      })
    }
  }
}
</script>
